package com.nft.qz.utils.result;

import lombok.Data;

@Data
public class R<T> {

    // 成功：{code:200,msg:"success",data:xxxx}
    // 失败：{code:40001,msg:"账号被冻结了",data:null}
    private Integer code;
    private Object msg;
    private String name;
    private T data;
    private R(){}

    private R (Integer code,Object msg,String name,T data){
        this.code = code;
        this.msg = msg;
        this.name = name;
        this.data = data;
    }

    /**
     * 成功的返回
     * @param data
     * @return
     */
    public static <T> R success(T data){
        return new R(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(),"SUCCESS",data);
    }

    /**
     * token续期使用
     * @param data
     * @return
     * @param <T>
     */
    public static <T> R successToken(T data){
        return new R(40066, ResultEnum.SUCCESS.getMsg(),"SUCCESS",data);
    }

    /**
     * 失败的返回
     * @param code
     * @param msg
     * @return
     */
    public static R fail(Integer code,Object msg){
        return new R(code,msg,"ERROR",null);
    }
    public static R fail(Integer code,String name,Object msg){
        return new R(code,msg,name,null);
    }

    /**
     * 失败的返回
     * @param resultCode
     * @return
     */
    public static R fail(IResultCode resultCode){
        return new R(resultCode.getCode(), resultCode.getMsg(),resultCode.getCodeDesc(),null);
    }

}
